/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package simhya.simengine.ode;

import org.apache.commons.math.ode.DerivativeException;
import simhya.model.flat.FlatModel;
import simhya.matheval.SymbolArray;

/**
 * This is the ODE function for a model in which all transitions are
 * continuously approximable and unguarded.
 * @author luca
 */
public class PureOdeFunction extends OdeFunction {

    public PureOdeFunction(FlatModel model) {
        super(model);
    }

    public void computeDerivatives(double t, double[] y, double[] yDot) throws DerivativeException {
        //resets derivatives to zero
        java.util.Arrays.fill(yDot, 0.0);
        //sets up the SymboArray dats structure for evaluation of flows
        SymbolArray vars = SymbolArray.getNewFastEvalSymbolArray(this.dimension);
        vars.setValuesReference(y);
        for (int i=0;i<this.continuousTransitions;i++) {
            int j = this.transitions[i];
            double x = rate[j].compute(vars);
            for (Stoichiometry s : stoich[j])
                yDot[s.variable] += s.coefficient * x;
        }
    }




}
